package linc.spring.demo;

import linc.spring.demo.bean.Role;
import linc.spring.demo.config.ApplicationConfiguration;
import linc.spring.demo.editor.StringToRolePropertyEditor;
import linc.spring.demo.service.UserService;
import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author yqlin
 * @date 2021/9/7 01:06
 * @description
 */
public class SpringPropertyEditorTest {
    @Test
    public void testPropertyEditor() {
        StringToRolePropertyEditor propertyEditor = new StringToRolePropertyEditor();
        propertyEditor.setAsText("linc");
        Role role = (Role) propertyEditor.getValue();
        // Role(id=9194214024089540013, name=linc)
        System.out.println(role);
    }

    @Test
    public void testCustomEditorConfigurer() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(ApplicationConfiguration.class);
        UserService userService = applicationContext.getBean(UserService.class);
        userService.test();
    }
}
